//
//  LoginUserInfo.h
//  Stampapa
//
//  Created by xiaoR on 15/9/22.
//  Copyright (c) 2015年 xiaoR. All rights reserved.
//
//  用户信息


#import "LoginUserInfo.h"
#import "NSString+Helper.h"
#import "NSNumber+Helper.h"


@implementation LoginUserInfo

/**
 * @brief  单例
 *
 * @param
 * @return
 */
+ (instancetype)sharedLoginUserInfo
{
    static dispatch_once_t once;
    static LoginUserInfo * loginUser;
    
    dispatch_once(&once, ^{
        if (!loginUser) {
            loginUser = [[LoginUserInfo alloc] init];
        }
    });
    
    return loginUser;
}

#pragma mark --私有方法
/**
 * @brief  保存用户信息到系统偏好
 *
 * @param
 * @return
 */
- (void)setUserName:(NSString *)userName
{
    [userName saveToUserDefaultsWithKey:kUserName_Key];
}

- (NSString *)loadStringFromDefaultsWithKey:(NSString *)key
{
    NSString * s = [[NSUserDefaults standardUserDefaults] stringForKey:key];
    
    return (s) ? s : @"";
}

/**
 * @brief  取出用户名
 *
 * @paramd
 * @return
 */
- (NSString *)userName
{
    return [NSString getStringFromUserDefaultsWithKey:kUserName_Key];
}

// 是否是第一次运行程序
- (void)setIsFirstRun:(BOOL)isFirstRun
{
    NSNumber * isFirst = [NSNumber numberWithBool:isFirstRun];
    [isFirst saveNumberToUserDefaultsWithKey:KApplication_FirstRunning_Key];
}

- (BOOL)isFirstRun
{
    NSNumber * isFirst = [NSNumber getNumberWithKey:KApplication_FirstRunning_Key];
    
    return [isFirst boolValue];
}
/**
 * @brief  保存自动登录参数
 *
 * @param
 * @return
 */
- (void)setIsAutoLogin:(BOOL)isAutoLogin
{
    NSNumber * number = [NSNumber numberWithBool:isAutoLogin];
    [number saveNumberToUserDefaultsWithKey:kUserAutoLogin_Key];
}

/**
 * @brief  获取自动登录参数
 *
 * @param
 * @return
 */
- (BOOL)isAutoLogin
{
    return [[NSNumber getNumberWithKey:kUserAutoLogin_Key] boolValue];
}

- (NSString *)memberAccessToken{
    
    return [NSString getStringFromUserDefaultsWithKey:kUerMemberAccessToken];
}

- (void)setMemberAccessToken:(NSString *)memberAccessToken{
    
    [memberAccessToken saveToUserDefaultsWithKey:kUerMemberAccessToken];
    
}

- (NSString * )member_seq {
    
    return [NSString getStringFromUserDefaultsWithKey:kUserMember_Seq ];
}

- (void)setMember_seq:(NSNumber *)member_seq {
    
    [member_seq saveNumberToUserDefaultsWithKey:kUserMember_Seq];
}

// 经度
- (NSString *)longitude
{
    return [self loadStringFromDefaultsWithKey :kLongitude_KEY];
}

// 保存经度
- (void)setLongitude:(NSString *)longitude
{
    [longitude saveToUserDefaultsWithKey:kLongitude_KEY];
}

// 纬度
- (NSString *)latitude
{
    return [self loadStringFromDefaultsWithKey:kLatitude_KEY];
}

// 保存纬度
- (void)setLatitude:(NSString *)latitude
{
    [latitude saveToUserDefaultsWithKey:kLatitude_KEY];
}
//账号
- (NSString *)joinkey
{
    return [self loadStringFromDefaultsWithKey:kJoinKey_KEY];
}
//保存账号
- (void)setJoinkey:(NSString *)joinkey
{
    [joinkey saveToUserDefaultsWithKey:kJoinKey_KEY];
}
//个推状态
- (BOOL)isGeTui
{
    NSNumber * GeTui = [NSNumber getNumberWithKey:KIsGeTui_KEY];
    return [GeTui boolValue];
}
//保存个推状态
- (void)setIsGeTui:(BOOL)isGeTui
{
    NSNumber * Getui = [NSNumber numberWithBool:isGeTui];
    [Getui saveNumberToUserDefaultsWithKey:KIsGeTui_KEY];
}
@end
